package test3;

import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        GoodFriend[] friend = new GoodFriend[3];
        friend[0] = new GoodFriend("张伞", 18, "女", "打游戏");
        friend[1] = new GoodFriend("李思", 25, "男", "singing");
        friend[2] = new GoodFriend("王舞", 22, "女", "跳舞");
        //计算平均年龄，低于平均年龄的有几个，并打印信息

        int len = friend.length;
        int sum = IntStream.range(0, len).map(i -> friend[i].getAge()).sum();
        int avg = sum / len;

        int count = 0,i = 0;

        while (i < len) {
            if (friend[i].getAge() < avg) {
                System.out.println(friend[i]);
                count++;
            }
            i++;
        }
        System.out.println("低于平均年龄的有"+count+"个人");

    }
}
